home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / TextReader.C < prev    next >
C/C++ Source or Header  |  1992-08-26  |  3KB  |  152 lines

  1. #ifdef __GNUG__
  2. #pragma implementation
  3. #endif
  4.  
  5. #include "TextReader.h"
  6.  
  7. #include "Class.h"
  8. #include "VObjectText.h"
  9. #include "RunArray.h"
  10. #include "VObject.h"
  11. #include "WindowSystem.h"
  12.  
  13. NewMetaImpl0(TextReader,Object);
  14.     
  15. TextReader::TextReader(StyledText *s, CharStyle *dfltcs, ParaStyle *dfltps)
  16. {
  17.     st= s;
  18.     runlen= paralen= pos= 0;
  19.     st->Cut(0, st->End());  // clear text
  20.     cstyles= st->GetCharStyles();
  21.     pstyles= st->GetParaStyles();
  22.     
  23.     CharDesc cd;
  24.     dfltcs->GetProperties(cd);
  25.     cd.GetFontProp(font, face, size);
  26.     ink= dfltcs->GetInk();
  27.     dfltps->CopyProperties(paraProp);
  28.     
  29.     cstyles->Insert(dfltcs, 0, cstyles->Size(), 1);
  30.     pstyles->Insert(dfltps, 0, cstyles->Size(), 1);
  31.     
  32.     flushed= FALSE;
  33. }
  34.  
  35. TextReader::~TextReader()
  36. {
  37.     if (!flushed)
  38.     Flush();
  39. }
  40.  
  41. void TextReader::Flush()
  42. {
  43.     if (runlen > 0) 
  44.     FlushCharProp();
  45.     if (paralen > 0) {
  46.     int end= pstyles->Size()-1; // terminator!
  47.     pstyles->Insert(new_ParaStyle(paraProp), end, end+1, paralen+1);
  48.     }        
  49.     flushed= TRUE;
  50. }
  51.  
  52. void TextReader::Append(byte b)
  53. {
  54.     st->AddChar(pos, b);
  55.     runlen++;
  56.     paralen++;
  57.     pos++;
  58.     if (Text::IsPara(b))
  59.     FlushParaProp();
  60. }
  61.     
  62. void TextReader::FlushCharProp()
  63. {
  64.     int end= cstyles->Size()-1;
  65.     cstyles->Insert(new_CharStyle(font, face, size, ink), end, end, runlen);
  66.     runlen= 0;
  67. }
  68.  
  69. void TextReader::FlushParaProp()
  70. {
  71.     int end= pstyles->Size()-1;
  72.     pstyles->Insert(new_ParaStyle(paraProp), end, end, paralen);
  73.     paralen= 0;
  74. }
  75.  
  76. void TextReader::SetParaProp(TxtParaProp what, int value)
  77. {
  78.     paraProp.SetProperty(what, value);
  79. }
  80.     
  81. void TextReader::SetParaProp(ParaDesc &pd)
  82. {
  83.     paraProp= pd;
  84. }
  85.  
  86. void TextReader::InsertVObject(VObject *vop)
  87. {
  88.     if (!st->IsKindOf(VObjectText))
  89.     return;
  90.     InsertVisualMark(new VObjectMark(vop));
  91. }
  92.  
  93.  
  94. void TextReader::InsertVisualMark(VisualMark *gip)
  95. {
  96.     if (!st->IsKindOf(VObjectText))
  97.     return;
  98.     VObjectText *vt= (VObjectText*)st;
  99.     
  100.     gip->CalcExtent();
  101.     gip->ChangeMark(pos, 1);
  102.     vt->GetVisualMarks()->Add(gip);
  103.     Append(cMarkChar);
  104. }
  105.  
  106.  
  107. void TextReader::SetFont(GrFont f)
  108. {
  109.     if (f == font)
  110.     return;
  111.     if (runlen > 0)
  112.     FlushCharProp(); 
  113.     font= f; 
  114. }
  115.     
  116. void TextReader::SetSize(int s)
  117.     if (s == size)
  118.     return;
  119.     if (runlen > 0)
  120.     FlushCharProp(); 
  121.     size= s; 
  122. }
  123.     
  124. void TextReader::SetInk(Ink *i)
  125.     if (i == ink)
  126.     return;
  127.     if (runlen > 0)
  128.     FlushCharProp(); 
  129.     ink= i; 
  130. }
  131.     
  132. void TextReader::SetFace(GrFace fc, int b)
  133. {
  134.     SetFace((GrFace) (b ? face | fc : face & ~fc));
  135. }
  136.     
  137. void TextReader::ToggleFace(GrFace fc)
  138. {
  139.     SetFace((GrFace) (face ^ fc));
  140. }
  141.     
  142. void TextReader::SetFace(GrFace fc)
  143.     if (fc == face)
  144.     return;
  145.     if (runlen > 0)
  146.     FlushCharProp(); 
  147.     face= fc; 
  148. }
  149.